<script>
/*
写一个类名字叫Rectangle（矩形）
构造方法应该采用4个参数 x,y,width,height
赋值给4个属性x,y,width,height
有toString方法，返回"(x=1, y=2, width=3, height=4)"
有5个getter属性
- left
- right
- top
- bottom
- area （面积）
*/

class Rectangle {
  constructor(x, y, width, height) {
    this.x = x
    this.y = y
    this.width = width
    this.height = height
  }
  toString() {
    const {x, y, width, height} = this
    return `(x=${x}, y=${y}, width=${width}, height=${height})`
  }
  get left() {return this.x}
  get right() {return this.x + this.width}
  get top() {return this.y}
  get bottom() {return this.y + this.height}
  get area() {return this.width * this.height}
}

let r = new Rectangle(100, 20, 50, 75)
r.left // 100
r.right // 150
r.top // 20
r.bottom // 95
r.area // 3750
</script>